package com.khalil.kkadmin.common.web;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class RespResult<T> {
    private String code;
    private String msg;
    private T data;

    public RespResult(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> RespResult<T> ok(T data) {
        return new RespResult<>("200", "操作成功", data);
    }

    public static <T> RespResult<T> error(String msg) {
        return new RespResult<>("500", msg, null);
    }

    public static <T> RespResult<T> error(String code, String msg) {
        return new RespResult<>(code, msg, null);
    }

    public static <T> RespResult<T> error(Code code) {
        return new RespResult<>(code.code, code.msg, null);
    }

    @Getter
    enum Code {
        SUCCESS("200", "操作成功"),
        ERROR("500", "操作失败");

        private final String code;
        private final String msg;

        Code(String code, String msg) {
            this.code = code;
            this.msg = msg;
        }
    }
}
